package com.atom.process.cnmuseum.bm.dao.process;


import com.atom.common.dao.AvensCommonDao;
import com.atom.common.exception.AvensNullPointerException;
import com.atom.common.mb.entity.gl.WhrlxxxDO;
import com.atom.common.remote.user.UserUtil;
import com.atom.process.cnmuseum.bm.entity.process.BmWhrlxxxProcessDO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class BmWhrlxxxProcessDao extends AvensCommonDao<BmWhrlxxxProcessDO> {
    public BmWhrlxxxProcessDO findByProcessInstanceId(String processId) {
        List<BmWhrlxxxProcessDO> list = super.findByProperty("processId", processId);
        if (list == null || list.size() == 0) {
            throw new AvensNullPointerException("ProcessDO is null where processId = " + processId);
        } else {
            return list.get(0);
        }
    }


    public void createPDO(UserUtil user, String processInstanceId, String title, WhrlxxxDO whrlxxx) {
        BmWhrlxxxProcessDO pdo = new BmWhrlxxxProcessDO();
        BeanUtils.copyProperties(whrlxxx, pdo, "id");
        pdo.setProcessId(processInstanceId);
        super.save(pdo);
    }

}
